cmake_minimum_required(VERSION 2.8.3)
project(feature_tracker)

set(CMAKE_BUILD_TYPE "Release")
# set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")

add_subdirectory(${PROJECT_SOURCE_DIR}/SuperPoint-SuperGlue-TensorRT/3rdparty/tensorrtbuffer)

find_package(catkin REQUIRED COMPONENTS
    roscpp
    std_msgs
    sensor_msgs
    cv_bridge
    camera_model
    )

find_package(OpenCV 4 REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(CUDA REQUIRED)
find_package(yaml-cpp REQUIRED)

catkin_package()

include_directories(
    ${catkin_INCLUDE_DIRS}
    ${PROJECT_SOURCE_DIR}/SuperPoint-SuperGlue-TensorRT
    ${PROJECT_SOURCE_DIR}/SuperPoint-SuperGlue-TensorRT/include
    ${OpenCV_INCLUDE_DIRS}
    ${EIGEN3_INCLUDE_DIRS}
    ${CUDA_INCLUDE_DIRS}
    ${YAML_CPP_INCLUDE_DIR}
    )

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(Eigen3)
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR}
)

add_library(superpointglue_lib SHARED
  SuperPoint-SuperGlue-TensorRT/src/super_point.cpp
  SuperPoint-SuperGlue-TensorRT/src/super_glue.cpp
)

target_link_libraries(superpointglue_lib
  nvinfer
  nvonnxparser
  ${OpenCV_LIBRARIES}
  ${CUDA_LIBRARIES}
  yaml-cpp
  tensorrtbuffer
)

add_executable(superpointglue_image SuperPoint-SuperGlue-TensorRT/inference_image.cpp)
add_executable(superpointglue_sequence SuperPoint-SuperGlue-TensorRT/inference_sequence.cpp)
add_executable(superpointglue_multithread SuperPoint-SuperGlue-TensorRT/inference_multithread.cpp)

target_link_libraries(superpointglue_image superpointglue_lib ${catkin_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(superpointglue_sequence  superpointglue_lib ${catkin_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(superpointglue_multithread  superpointglue_lib ${catkin_LIBRARIES} ${OpenCV_LIBS})

add_executable(feature_tracker
    src/feature_tracker_node.cpp
    src/parameters.cpp
    src/feature_tracker.cpp
    ORBLib/ORBextractor.cpp
    )

target_link_libraries(feature_tracker ${catkin_LIBRARIES} ${OpenCV_LIBS} superpointglue_lib)
